package com.example.service;

import com.google.common.base.Function;
import com.google.common.collect.MapMaker;

import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;

public class SqnService {
    private Map<String, AtomicLong> sqns = (new MapMaker()).makeComputingMap(new Function<String, AtomicLong>() {
        public AtomicLong apply(String from) {
            return new AtomicLong(1L);
        }
    });

    public SqnService() {
    }

    public long getSqn(String key) {
        return ((AtomicLong)this.sqns.get(key)).getAndIncrement();
    }

    public long reset(String key) {
        return ((AtomicLong)this.sqns.get(key)).getAndSet(1L);
    }
}
